package com.qingcheng.consumer;


import com.alibaba.fastjson.JSON;
import com.qingcheng.pojo.goods.StockBack;
import com.qingcheng.pojo.order.OrderItem;
import com.qingcheng.service.goods.StockBackService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class BackMessageConsumer implements MessageListener {
    @Autowired
    private StockBackService stockBackService;
    @Override
    public void onMessage(Message message) {
        try {
            //提取消息
            String jsonString = new String(message.getBody());
            List<OrderItem> orderItems = JSON.parseArray(jsonString, OrderItem.class);
            System.out.println("开始添加回滚数据");
            stockBackService.addList(orderItems);
            System.out.println("添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            //记录日志人工干预
        }
    }
}
